package com.zzyk.microCloud.controller;

import com.github.pagehelper.PageInfo;
import com.zzyk.main.configuration.exception.UserException;
import com.zzyk.main.controller.BaseController;
import com.zzyk.main.model.pojo.Organization;
import com.zzyk.main.model.pojo.SysUser;
import com.zzyk.main.model.vo.Message;
import com.zzyk.main.model.vo.OrganizationInfo;
import com.zzyk.main.service.ISysOrganizationService;
import com.zzyk.main.utils.FTPUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping({"/sys/org"})
public class SysOrganizationController extends BaseController {

    @Autowired
    private ISysOrganizationService organizationService;

    @Autowired
    private FTPUtils ftp;

    @Value("${ftp.logoDir}")
    private String logoDir;
    @Value("${ftp.photoDir}")
    private String photoDir;



    @RequestMapping("list")
    public Message list(Organization organization) throws UserException {
        SysUser sysUser = currentUser();
        organization.setArea(sysUser.getArea());
        setPage();
        List<OrganizationInfo> list = organizationService.list(organization);
        PageInfo<OrganizationInfo> info = new PageInfo<>(list);
        return Message.success("组织机构查询成功")
                .addData("data", info.getList())
                .addData("total", info.getTotal())
                .addData("pages", info.getPages());
    }

    @RequestMapping("get")
    public Message get(@RequestParam("ids") String[] ids) {
        return Message.success().addData("data", organizationService.getList(ids));
    }

    @RequestMapping("info")
    public Message info(@RequestParam("id") Integer id) {
        return Message.success().addData("data", organizationService.get(id));
    }


    @RequestMapping("del")
    @Transactional
    public Message del(@RequestParam("id") Integer id) {
        return Message.success().addData("data", organizationService.del(id));
    }
}
